/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var KEY_UP = "w";
var KEY_DOWN = "s";
var KEY_LEFT = "a";
var KEY_RIGHT = "d";
// Constants to match JQuery Hotkeys event value type.
var KEY_TYPE_UP = "keyup";
var KEY_TYPE_DOWN = "keydown";
var old_msg = "";
var keys = new Array();
var isMoveLeft = false;
var isMoveRight = false;
var isMoveUp = false;
var isMoveDown = false;
function keyEvent(evt)
{
    var keyName = String.fromCharCode(evt.keyCode).toLowerCase();
    var type = "";
    //alert(evt.keyCode);
    if (evt.type == KEY_TYPE_DOWN) {
        type = "d";
    } else if (evt.type == KEY_TYPE_UP) {
        type = "u";
    }
    if (evt.keyCode == 37) {
        keyName = KEY_LEFT;
        if (type == "d") {
            isMoveLeft = true;
        } else {
            isMoveLeft = false;
        }
    }
    if (evt.keyCode == 38) {
        keyName = KEY_UP;
        if (type == "d") {
            isMoveUp = true;
        } else {
            isMoveUp = false;
        }

    }
    if (evt.keyCode == 39) {
        keyName = KEY_RIGHT;
        if (type == "d") {
            isMoveRight = true;
        } else {
            isMoveRight = false;
        }
    }
    if (evt.keyCode == 40) {
        keyName = KEY_DOWN;
        if (type == "d") {
            isMoveDown = true;
        } else {
            isMoveDown = false;
        }
    }
    if (evt.keyCode >= 49 && evt.keyCode < 59) {
        if (type == "d") {

        } else {
            ws.sendMessage("gm" + (evt.keyCode - 48));
        }
    }
    if (evt.keyCode == 81) {
        if (type == "d") {

        } else {
            exitRoom();
        }
    }
    if (evt.keyCode == 32) {
        if (type == "d") {

        } else {
            for (var j = 0; j < objects.heroes.length; j++) {
                if (objects.heroes[j].id == meId) {
                    objects.heroes[j].next_animation = "atack1";
                }
            }

        }
    }
    //
    //var msg = 'ke' + type + keyName;
    // if (old_msg != msg)
    //document.ws.sendMessage(msg);
    //old_msg = msg;
}
